﻿using System;
using HoundSharp;


namespace shserver
{
    public class SignalHound
    {
        private static SignalHound _instance = null;
        double myStartFrequency = 248.91e6;
        double myStopFrequency = 249.09e6;
        int myFFTSize = 512; //50 KHz RBW
        int returnCount = 0;
        double[] myTrace;

        public static SignalHound Instance
        {
            get
            {
                if(_instance == null)
                {
                    _instance = new SignalHound();
                }
                return _instance;
            }
        }

        public int init()
        {
            return SA44B_Device.SHAPI_Initialize();
        }

        public int configure(double attenVal = 10.0, int mixerBand = 1, int sensitivity = 0, int decimation = 1, int IF_Path = 0, int ADC_clock = 0)
        {
            return SA44B_Device.SHAPI_Configure(attenVal, mixerBand, sensitivity, decimation, IF_Path, ADC_clock);
        }

        public void reset()
        {
            SA44B_Device.SHAPI_CyclePowerOnExit();
        }

        public int slowSweepCount()
        {
            int count = SA44B_Device.SHAPI_GetSlowSweepCount(myStartFrequency, myStopFrequency, myFFTSize);
            myTrace = new double[count + 4];
            return count;
        }

        public void slowSleep()
        {
            SA44B_Device.SHAPI_GetSlowSweep(myTrace, myStartFrequency, myStopFrequency, ref returnCount, myFFTSize, 2, 0);
        }

        public double[] getData()
        {
            //TODO: Capture errors
            slowSweepCount();
            slowSleep();
            return myTrace;
        }
    }
}